import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../views/Login";
import Home from "../views/Home";
import CaiForm from "../views/good/CaiForm";
import CaiList from "../views/good/CaiList";
import GoodList from "../views/good/GoodList";
Vue.use(VueRouter)

const routes = [
  {path:"/",redirect:"/login"},
 {name:"登录",path:"/login",component:Login} ,
  {name:"主页",path:"/home",component: Home,children:[
      {name:"采购",path:"/cai",component:CaiForm},
      {name:"列表",path: "/cailist",component:CaiList },
      {name:"列表1",path: "/goodlist",component:GoodList }
    ]}
]

const router = new VueRouter({
  routes
})
router.beforeEach(function (to,from,next) {
    if(to.path=="/login"){
      return next();
    }
    let user=sessionStorage.getItem("user");
    if(user){
      return next();
    }
    return next("/login")
})

export default router
